import Vue from "vue";
import VueRouter from "vue-router";

import About from "../views/About.vue";
import Home from "../views/Home";
import Message from "../views/Message";
import News from "../views/News";

import MessageDetail from "../views/MessageDetail";

Vue.use(VueRouter);

const Routers = [
  {
    path: '/about',
    component: About

  },

  {
    path: '/home',
    component: Home,
    children: [
      {
        path: 'message',
        component: Message,
        meta: {
          title: '消息'
        },
        children:[{
          path: 'detail/:id',
          component: MessageDetail,
          meta: {
            title: '消息详情'
          }
        }]
      },
      {
        path: '/home/news',
        component: News,
        meta: {
          title: '新闻'
        }
      },
      {
        path: '',                       //设置进入默认路由
        redirect: '/home/news',
        meta: {
          title: '新闻'
        }
      }
    ]
  },
  {
    path: '/',                          //设置进入默认路由
    redirect: '/about'
  },
];
const RouterConfig = {
  mode: 'history',
  linkActiveClass: 'active',
  routes: Routers
};

const router = new VueRouter(RouterConfig);
router.beforeEach((to, from, next) => {
  window.document.title = to.meta.title; // 修改网页标题
  next(); // 调用改方法后，才能进入下一个钩子
});

export default router;

